﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Security.Policy;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
//using FastReport.DevComponents.DotNetBar.Controls;
using Infragistics.Documents.Excel.Charts;
using Kingdee.BOS;
using Kingdee.BOS.WebApi.Client;
using Kingdee.BOS.WebApi.DataEntify;
using NPOI.SS.Formula.Functions;
using static System.Windows.Forms.VisualStyles.VisualStyleElement;


namespace biaoqian
{
    public partial class Form1 : Form
    {
        Class1 one = new Class1();
        LDhuoyunEntities db = new LDhuoyunEntities();
        public Form1()
        {
            InitializeComponent();
        }
        /// <summary>
        /// 提交运单按钮
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button3_Click(object sender, EventArgs e)
        {
            Waybill_submission();
        }
        /// <summary>
        /// 页面加载
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Form1_Load(object sender, EventArgs e)
        {
            label2.Visible = false;
            Get_Shipping_note();
            
            Get_carrier();
            label2.Text = "1";
            Cet_vehicle();
            //Get_Shipping_note_number();
            qqq();
        }
        /// <summary>
        /// 点击选择按钮
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button1_Click(object sender, EventArgs e)
        {
            Get_dataGridView1();
        }

        /// <summary>
        /// 单号下拉列表改变时触发
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void comboBox1_KeyUp(object sender, KeyEventArgs e)
        {
            //comboBox1.Items.Clear();
            DateTime now = DateTime.Now;
            string currentDateTime = now.ToString("yyyy-MM-dd HH:mm:ss");
            K3CloudApi client = new K3CloudApi();
            //用于记录结果
            StringBuilder Info = new StringBuilder();
            //业务对象标识
            string formId = "SAL_DELIVERYNOTICE";
            //查询字段集合，即返回哪些数据，不能为空，根据不同业务单据填写不同的字段名，以下仅为示例
            string fieldKeys = "FBillNo";
            //请求参数，示例使用的是SDK提供的模板类，还可以使用字符串拼接等方式  and FCancelStatus='A'  and FPlanDeliveryDate >'" + currentDateTime + "'
            var ZBLx = comboBox1.Text;
            var param = new QueryParam()
            {
                FormId = formId,
                FieldKeys = fieldKeys,
                FilterString = "FBillNo like'%" + ZBLx + "%'",
                TopRowCount = 0,
                StartRow = 0,
                Limit = 120,
                OrderString = "FBillNo",
            };
            //调用接口
            var result = client.ExecuteBillQuery(param.ToJson());
            DataTable dataTable = one.ERP_id();
            
            foreach (var item in result)
            {
                bool index = false;
                if (dataTable.Rows.Count == 0)
                {
                    comboBox1.Items.Add(item[0]);
                }
                else
                {
                    foreach (DataRow obj in dataTable.Rows)
                    {
                        string a = obj.ItemArray[0].ToString();
                        string b = item[0].ToString();
                        if (a == b)
                        {
                            index = true;
                            break;

                        }
                    }
                    if (index == false)
                    {
                        comboBox1.Items.Add(item[0]);
                    }

                }
                
            }
        }

        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            //Get_Shipping_note();
        }


        /// <summary>
        /// 点击创建运单按钮
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button2_Click(object sender, EventArgs e)
        {
            double zl = 0;
            double tj = 0;

            double z2l = 0;
            double t2j = 0;
            foreach (DataGridViewRow hy in dataGridView2.Rows)
            {
                tj += double.Parse(hy.Cells[4].Value.ToString());
                zl += double.Parse(hy.Cells[3].Value.ToString())/1000;
            }

            if (dataGridView2.Rows.Count != 0)
            {
                if (dataGridView2.Rows.Count == 1)
                {
                    int index = 0;
                    foreach (DataGridViewRow cls in dataGridView3.Rows)
                    {
                        double zz = double.Parse(cls.Cells[5].Value.ToString());
                        double rj = double.Parse(cls.Cells[6].Value.ToString());
                        if (zz > zl && rj > tj)
                        {
                            index++;
                        }
                        z2l += zz;
                        t2j += rj;

                    }
                    if (index != 0)
                    {
                        JS_pcdc();
                    }
                    else
                    {
                        string cydw = comboBox2.Text;
                        if (z2l < zl || t2j < tj)
                        {
                            MessageBox.Show(cydw + "运载能力不足,请选择其他承运单位");
                        }
                        else
                        {
                            JS_dc();
                        }

                    }
                }
                else
                {
                    int index = 0;
                    foreach (DataGridViewRow cls in dataGridView3.Rows)
                    {
                        double zz = double.Parse(cls.Cells[5].Value.ToString());
                        double rj = double.Parse(cls.Cells[6].Value.ToString());
                        if (zz > zl && rj > tj)
                        {
                            index++;
                        }


                    }
                    if (index != 0)
                    {
                        JS_pc();
                    }
                    else
                    {
                        MessageBox.Show("所选超过最大车辆运载能力,请重新配置拼车");
                    }
                }
            }
            else
            {
                MessageBox.Show("请选择发货单号创建运单");
            }
            
            
        }

        /// <summary>
        /// 计算拼车运费的
        /// </summary>
        private void JS_pc()
        {
            double num_W = 0;
            double num_V = 0;
            double num_S = 0;
            double num_S2 = 0;
            string freight = "";
            double number = 0;
            double jsglsd;
            double num;
            double sjhdh = 0;
            string cph = "";
            string sqdh = "";
            string kh = "";
            string hw = "";
            string dz = "";
            string cydw = "";
            double min_zz = 10000000;
            int cl = 0;
            foreach (DataGridViewRow item in dataGridView3.Rows)
            {
                double min = double.Parse(item.Cells[5].Value.ToString());
                if (min_zz > min)
                {
                    min_zz = min;
                    cl = int.Parse(item.Cells[0].Value.ToString());
                    
                }

            }
            foreach (DataGridViewRow item in dataGridView2.Rows)
            {
                if (sqdh == "")
                {
                    sqdh += item.Cells[1].Value.ToString();
                }
                else
                {
                    sqdh += "/" + item.Cells[1].Value.ToString();
                }
                if (kh == "")
                {
                    kh += item.Cells[5].Value.ToString();
                }
                else
                {
                    kh += "/" + item.Cells[5].Value.ToString();
                }
                if (hw == "")
                {
                    hw += item.Cells[7].Value.ToString();
                }
                else
                {
                    hw += "/" + item.Cells[7].Value.ToString();
                }
                if (dz == "")
                {
                    dz += item.Cells[6].Value.ToString();
                }
                else
                {
                    dz += "/" + item.Cells[6].Value.ToString();
                }
                num_S = double.Parse(item.Cells[2].Value.ToString());
                num_S2 += double.Parse(item.Cells[2].Value.ToString());
                num_V = double.Parse(item.Cells[4].Value.ToString());
                num_W = double.Parse(item.Cells[3].Value.ToString())/1000;


                CLSJ clsj = db.CLSJ.Where(x => x.cl_id == cl).FirstOrDefault();
                cph = clsj.cl_cp;
                int cx =int.Parse(clsj.cl_cx.ToString()) ;
                List<YFJG> yf = db.YFJG.Where(a => a.jw_cx == cx && a.jw_bian == "阶梯").ToList();
                YFJG yf_qb = db.YFJG.Where(a => a.jw_cx == cx && a.jw_bian == "起步").FirstOrDefault();
                YFJG yf_zg = db.YFJG.Where(a => a.jw_cx == cx && a.jw_bian == "最高").FirstOrDefault();
                

                if (double.Parse(clsj.cl_rj) >= num_V && double.Parse(clsj.cl_zz) >= num_W)
                {
                    if (yf_qb != null && yf_zg != null)
                    {
                        number = 0;
                        jsglsd = 0;
                        num = 0;
                        if (num_S > double.Parse(yf_qb.jw_jt))
                        {
                            number += double.Parse(yf_qb.jw_jg.ToString());
                            jsglsd += double.Parse(yf_qb.jw_jt);

                            if (num_S > double.Parse(yf_zg.jw_jt))
                            {
                                foreach (YFJG ffjg in yf)
                                {

                                    num = (double.Parse(ffjg.jw_jt)) - jsglsd;
                                    number += num * double.Parse(ffjg.jw_jg.ToString());
                                    jsglsd += num;
                                }

                                number = double.Parse(yf_zg.jw_jt) * double.Parse(yf_zg.jw_jg.ToString());
                                freight = number.ToString();
                            }
                            else
                            {
                                foreach (YFJG ffjg in yf)
                                {
                                    if (num_S >= double.Parse(ffjg.jw_jt))
                                    {
                                        num = double.Parse(ffjg.jw_jt) - jsglsd;
                                        number += num * double.Parse(ffjg.jw_jg.ToString());
                                        jsglsd += num;
                                    }
                                    else
                                    {
                                        freight = number.ToString();
                                    }

                                }
                            }
                        }
                        else
                        {
                            number += double.Parse(yf_qb.jw_jg.ToString());
                            freight = number.ToString();
                        }
                    }
                }
                sjhdh += double.Parse(freight);
            }

            
            DateTime now = DateTime.Now;
            string formattedDate = now.ToString("yyyy-MM-dd");
            int count = db.YDXX.Where(x => x.yd_cjrq == formattedDate).Count();
            string dangt = "";
            if (count.ToString().Length == 1)
            {
                dangt = "000" + count.ToString();
            }
            else if (count.ToString().Length == 2)
            {
                dangt = "00" + count.ToString();
            }
            else if (count.ToString().Length == 3)
            {
                dangt = "0" + count.ToString();
            }
            string fhdh = "FH-" + formattedDate + "-" + dangt;
            DataTable dataTable = one.Yund_xx();
            dataTable.Rows.Add(sqdh, kh, dz, hw, formattedDate, fhdh, cydw, "1", num_S2, sjhdh, cph);
            dataGridView4.DataSource = dataTable;

        }





        /// <summary>
        /// 普通运费
        /// </summary>
        private void JS_pcdc()
        {
            double num_W=0;
            double num_V=0;
            double num_S=0;
            string freight = "";
            double number=0;
            double jsglsd;
            double num;
            double sjhdh = 100000000;
            string cph = "";
            string sqdh = "";
            string kh = "";
            string hw = "";
            string dz = "";
            string cydw = "";
            foreach (DataGridViewRow item in dataGridView2.Rows)
            {
                if (sqdh=="")
                {
                    sqdh += item.Cells[1].Value.ToString();
                }
                else
                {
                    sqdh += "/" + item.Cells[1].Value.ToString();
                }
                if (kh == "")
                {
                    kh += item.Cells[5].Value.ToString();
                }
                else
                {
                    kh += "/" + item.Cells[5].Value.ToString();
                }
                if (hw == "")
                {
                    hw += item.Cells[7].Value.ToString();
                }
                else
                {
                    hw += "/" + item.Cells[7].Value.ToString();
                }
                if (dz == "")
                {
                    dz += item.Cells[6].Value.ToString();
                }
                else
                {
                    dz += "/" + item.Cells[6].Value.ToString();
                }
                num_S += double.Parse(item.Cells[2].Value.ToString());
                num_V += double.Parse(item.Cells[4].Value.ToString());
                num_W += double.Parse(item.Cells[3].Value.ToString())/1000;
            }

            foreach (DataGridViewRow item in dataGridView3.Rows)
            {
                int cl = int.Parse(item.Cells[0].Value.ToString());
                CLSJ clsj = db.CLSJ.Where(x => x.cl_id == cl).FirstOrDefault();
                int cx = db.CLSJ.Where(x => x.cl_id == cl).FirstOrDefault().cl_id;
                List<YFJG> yf = db.YFJG.Where(a => a.jw_cx == cx && a.jw_bian == "阶梯").ToList();
                YFJG yf_qb = db.YFJG.Where(a => a.jw_cx == cx && a.jw_bian == "起步").FirstOrDefault();
                YFJG yf_zg = db.YFJG.Where(a => a.jw_cx == cx && a.jw_bian == "最高").FirstOrDefault();

                if(double.Parse(clsj.cl_rj) >= num_V && double.Parse(clsj.cl_zz)>= num_W)
                {
                    if (yf_qb != null && yf_zg != null)
                    {
                        number = 0;
                        jsglsd = 0;
                        num = 0;
                        if (num_S > double.Parse(yf_qb.jw_jt))
                        {
                            number += double.Parse(yf_qb.jw_jg.ToString());
                            jsglsd += double.Parse(yf_qb.jw_jt);

                            if (num_S > double.Parse(yf_zg.jw_jt))
                            {
                                foreach (YFJG ffjg in yf)
                                {

                                    num = (double.Parse(ffjg.jw_jt)) - jsglsd;
                                    number += num * double.Parse(ffjg.jw_jg.ToString());
                                    jsglsd += num;
                                }

                                number += (num_S-double.Parse(yf_zg.jw_jt)) * double.Parse(yf_zg.jw_jg.ToString());
                                freight = number.ToString();
                            }
                            else
                            {
                                foreach (YFJG ffjg in yf)
                                {

                                    if (num_S >= double.Parse(ffjg.jw_jt))
                                    {
                                        num = double.Parse(ffjg.jw_jt) - jsglsd;
                                        number += num * double.Parse(ffjg.jw_jg.ToString());
                                        jsglsd += num;
                                    }
                                    else
                                    {
                                        freight = number.ToString();
                                    }

                                }
                            }
                        }
                        else
                        {
                            number += double.Parse(yf_qb.jw_jg.ToString());
                            freight = number.ToString();
                        }
                    }
                    if (sjhdh > double.Parse(freight))
                    {
                        sjhdh = double.Parse(freight);
                        cph = clsj.cl_cp;
                        cydw = clsj.CYDW.cy_name;
                    }
                }
                
            }
            DateTime now = DateTime.Now;
            string formattedDate = now.ToString("yyyy-MM-dd");
            int count = db.YDXX.Where(x=>x.yd_cjrq== formattedDate).Count();
            string dangt = "";
            if (count.ToString().Length == 1)
            {
                dangt = "000" + count.ToString();
            }
            else if (count.ToString().Length == 2)
            {
                dangt = "00" + count.ToString();
            }
            else if (count.ToString().Length == 3)
            {
                dangt = "0" + count.ToString();
            }
            string fhdh = "FH-" + formattedDate +"-"+ dangt;
            DataTable dataTable = one.Yund_xx();
            dataTable.Rows.Add(sqdh, kh,dz,hw, formattedDate, fhdh, cydw, "1", num_S, sjhdh, cph);
            dataGridView4.DataSource = dataTable;

        }
        /// <summary>
        /// 计算多车的运费价格
        /// </summary>
        private void JS_dc()
        {
            double temp = 100000;
            double temp_cpg = 0;
            //string ccc = cs;
            char[] delimiterChars = { ' ' };
            //string[] words = ccc.Split(delimiterChars);
            string cphh = "";
            double number = 0;
            double number2 = 0;
            double jsglsd = 0;
            double num = 0;
            double zaizhong2 = 0;
            double rongji2 = 0;
            double biaoj = 0;
            int xxx = 0;

            double num_W = 0;
            double num_V = 0;
            double num_S = 0;

            string cph = "";
            string cph3 = "";
            string sqdh = "";
            string kh = "";
            string hw = "";
            string dz = "";
            string cydw = "";
            foreach (DataGridViewRow item in dataGridView2.Rows)
            {
                if (sqdh == "")
                {
                    sqdh += item.Cells[1].Value.ToString();
                }
                else
                {
                    sqdh += "/" + item.Cells[1].Value.ToString();
                }
                if (kh == "")
                {
                    kh += item.Cells[5].Value.ToString();
                }
                else
                {
                    kh += "/" + item.Cells[5].Value.ToString();
                }
                if (hw == "")
                {
                    hw += item.Cells[7].Value.ToString();
                }
                else
                {
                    hw += "/" + item.Cells[7].Value.ToString();
                }
                if (dz == "")
                {
                    dz += item.Cells[6].Value.ToString();
                }
                else
                {
                    dz += "/" + item.Cells[6].Value.ToString();
                }
                num_S = double.Parse(item.Cells[2].Value.ToString());
                num_V += double.Parse(item.Cells[4].Value.ToString());
                num_W += double.Parse(item.Cells[3].Value.ToString())/1000;
            }

            for (double zl2 = num_W, tj2 = num_V; zl2 >= 0 || tj2 >= 0; zl2 -= zaizhong2, tj2 -= rongji2)
            {
                temp = 1000000;
                foreach (DataGridViewRow cls in dataGridView3.Rows)
                {
                    if (cls.Cells[1].Value.ToString() != "")
                    {
                        number = 0;
                        jsglsd = 0;
                        string cph2 = cls.Cells[1].Value.ToString();
                        CLSJ cl = db.CLSJ.Where(x => x.cl_cp == cph2).FirstOrDefault();
                        double zaizhong = double.Parse(cl.cl_zz);
                        double rongji = double.Parse(cl.cl_rj);
                        List<YFJG> yf = db.YFJG.Where(a => a.jw_cx == cl.cl_cx && a.jw_gs == cl.cl_ss && a.jw_bian == "阶梯").ToList();
                        YFJG yf_qb = db.YFJG.Where(a => a.jw_cx == cl.cl_cx && a.jw_gs == cl.cl_ss && a.jw_bian == "起步").FirstOrDefault();
                        YFJG yf_zg = db.YFJG.Where(a => a.jw_cx == cl.cl_cx && a.jw_gs == cl.cl_ss && a.jw_bian == "最高").FirstOrDefault();

                        if (yf_qb != null && yf_zg != null)
                        {
                            if (num_S > double.Parse(yf_qb.jw_jt))
                            {
                                number += double.Parse(yf_qb.jw_jg.ToString());
                                jsglsd += double.Parse(yf_qb.jw_jt);

                                if (num_S > double.Parse(yf_zg.jw_jt))
                                {
                                    foreach (YFJG ffjg in yf)
                                    {

                                        num = (int.Parse(ffjg.jw_jt)) - jsglsd;
                                        number += num * double.Parse(ffjg.jw_jg.ToString());
                                        jsglsd += num;
                                    }
                                    number = int.Parse(yf_zg.jw_jt) * int.Parse(yf_zg.jw_jg.ToString());
                                }
                                else
                                {
                                    foreach (YFJG ffjg in yf)
                                    {
                                        if (num_S >= int.Parse(ffjg.jw_jt))
                                        {
                                            num = int.Parse(ffjg.jw_jt) - jsglsd;
                                            number += num * double.Parse(ffjg.jw_jg.ToString());
                                            jsglsd += num;
                                        }
                                        else
                                        {
                                            break;
                                        }
                                    }
                                }
                            }
                            else
                            {
                                number += int.Parse(yf_qb.jw_jg.ToString());
                            }

                            if (tj2 >= rongji)
                            {
                                if (number / double.Parse(cl.cl_rj) < temp)
                                {
                                    temp = number / double.Parse(cl.cl_zz);
                                    temp_cpg = cl.cl_id;
                                    zaizhong2 = zaizhong;
                                    rongji2 = rongji;
                                    biaoj = number;
                                    cph = cl.cl_cp;
                                }
                            }
                            else
                            {
                                if (number / tj2 < temp)
                                {
                                    temp = number / tj2;
                                    temp_cpg = cl.cl_id;
                                    zaizhong2 = zaizhong;
                                    rongji2 = rongji;
                                    biaoj = number;
                                    cph = cl.cl_cp;
                                }
                            }
                        }
                    }
                }
                number2 += biaoj;
                if (cph3 == "")
                {
                    cph3 += cph;
                }
                else
                {
                    cph3 += "/" + cph;
                }
                xxx++;
            }

            DateTime now = DateTime.Now;
            string formattedDate = now.ToString("yyyy-MM-dd");
            int count = db.YDXX.Where(x => x.yd_cjrq == formattedDate).Count();
            string dangt = "";
            if (count.ToString().Length == 1)
            {
                dangt = "000" + count.ToString();
            }
            else if (count.ToString().Length == 2)
            {
                dangt = "00" + count.ToString();
            }
            else if (count.ToString().Length == 3)
            {
                dangt = "0" + count.ToString();
            }
            string fhdh = "FH-" + formattedDate + "-" + dangt;
            DataTable dataTable = one.Yund_xx();
            dataTable.Rows.Add(sqdh, kh, dz, hw, formattedDate, fhdh, cydw, xxx.ToString(), num_S, number2.ToString(), cph3);
            dataGridView4.DataSource = dataTable;

        }


        /// <summary>
        /// 将运单信息提交到数据库
        /// </summary>
        private void Waybill_submission()
        {
            int num = 0;
            if (dataGridView4.RowCount > 0)
            {
                foreach(DataGridViewRow dgv4 in dataGridView4.Rows)
                {
                    YDXX yd = new YDXX()
                    {
                        yd_fhdh= dgv4.Cells[0].Value.ToString(),
                        yd_kh= dgv4.Cells[1].Value.ToString(),
                        yd_shdz= dgv4.Cells[2].Value.ToString(),
                        yd_hw= dgv4.Cells[3].Value.ToString(),
                        yd_cjrq= dgv4.Cells[4].Value.ToString(),
                        yd_shdh= dgv4.Cells[5].Value.ToString(),
                        yd_cydw= dgv4.Cells[6].Value.ToString(),
                        yd_cc= dgv4.Cells[7].Value.ToString(),
                        yd_gls= dgv4.Cells[8].Value.ToString(),
                        yd_yf= dgv4.Cells[9].Value.ToString(),
                        yd_cph= dgv4.Cells[10].Value.ToString(),
                        yd_sh="审核中",
                    };
                    db.YDXX.Add(yd);
                    num += db.SaveChanges();
                }
            }
            if (num != 0)
            {

                MessageBox.Show("上传成功");
                // UploadTest();
            }
            else
            {
                MessageBox.Show("上传失败");
            }
        }

        /// <summary>
        /// 获取发货通知单表里的数据放到带生成运单表
        /// </summary>
        public void UploadTest()
        {
            string yd_fhdh;//发货单号
            string yd_kh;//客户名称
            string yd_shdz;//收获地址
            string yd_hw;//货物名称
            string yd_shdh;//送货单号
            string yd_cydw;//承运单位
            string yd_cc;//车次
            string yd_gls;//公里数
            string yd_yf;//运费
            string yd_cph;//
            string yd_cjrq;//创建日期
            foreach (DataGridViewRow dgv4 in dataGridView4.Rows)
            {
                yd_fhdh = dgv4.Cells[0].Value.ToString();
                yd_kh = dgv4.Cells[1].Value.ToString();
                yd_shdz = dgv4.Cells[2].Value.ToString();
                yd_hw = dgv4.Cells[3].Value.ToString();
                yd_cjrq = dgv4.Cells[4].Value.ToString();
                yd_shdh = dgv4.Cells[5].Value.ToString();
                yd_cydw = dgv4.Cells[6].Value.ToString();
                yd_cc = dgv4.Cells[7].Value.ToString();
                yd_gls = dgv4.Cells[8].Value.ToString();
                yd_yf = dgv4.Cells[9].Value.ToString();
                yd_cph = dgv4.Cells[10].Value.ToString();
            }
            K3CloudApi client = new K3CloudApi();
            string jsons = "{\r\n    \"NeedUpDateFields\": [],\r\n    \"NeedReturnFields\": [],\r\n    \"IsDeleteEntry\": \"true\",\r\n    \"SubSystemId\": \"\",\r\n    \"IsVerifyBaseDataField\": \"false\",\r\n    \"IsEntryBatchFill\": \"true\",\r\n    \"ValidateFlag\": \"true\",\r\n    \"NumberSearch\": \"true\",\r\n    \"IsAutoAdjustField\": \"false\",\r\n    \"InterationFlags\": \"\",\r\n    \"IgnoreInterationFlag\": \"\",\r\n    \"IsControlPrecision\": \"false\",\r\n    \"ValidateRepeatJson\": \"false\",\r\n    \"Model\": {\r\n        \"FID\": 0,\r\n        \"FBillTypeID\": {\r\n            \"FNUMBER\": \"\"\r\n        },\r\n        \"FBillNo\": \"\",\r\n        \"FISINIT\": \"false\",\r\n        \"FDATE\": \"1900-01-01\",\r\n        \"FENDDATE_H\": \"1900-01-01\",\r\n        \"FDOCUMENTSTATUS\": \"\",\r\n        \"FSUPPLIERID\": {\r\n            \"FNumber\": \"\"\r\n        },\r\n        \"FCURRENCYID\": {\r\n            \"FNumber\": \"\"\r\n        },\r\n        \"FPayConditon\": {\r\n            \"FNumber\": \"\"\r\n        },\r\n        \"FISPRICEEXCLUDETAX\": \"false\",\r\n        \"FSourceBillType\": \"\",\r\n        \"FBUSINESSTYPE\": \"\",\r\n        \"FISTAX\": \"false\",\r\n        \"FSETTLEORGID\": {\r\n            \"FNumber\": \"\"\r\n        },\r\n        \"FPAYORGID\": {\r\n            \"FNumber\": \"\"\r\n        },\r\n        \"FSetAccountType\": \"\",\r\n        \"FISTAXINCOST\": \"false\",\r\n        \"FAP_Remark\": \"\",\r\n        \"FISHookMatch\": \"false\",\r\n        \"FACCOUNTSYSTEM\": {\r\n            \"FNumber\": \"\"\r\n        },\r\n        \"FPURCHASEDEPTID\": {\r\n            \"FNumber\": \"\"\r\n        },\r\n        \"FPURCHASERGROUPID\": {\r\n            \"FNumber\": \"\"\r\n        },\r\n        \"FPURCHASERID\": {\r\n            \"FNumber\": \"\"\r\n        },\r\n        \"FCancelStatus\": \"\",\r\n        \"FISBYIV\": \"false\",\r\n        \"FISGENHSADJ\": \"false\",\r\n        \"FMatchMethodID\": 0,\r\n        \"FISINVOICEARLIER\": \"false\",\r\n        \"FScanPoint\": {\r\n            \"FNUMBER\": \"\"\r\n        },\r\n        \"FBILLMATCHLOGID\": 0,\r\n        \"FWBOPENQTY\": \"false\",\r\n        \"FPRESETBASE1\": {\r\n            \"FNUMBER\": \"\"\r\n        },\r\n        \"FPRESETBASE2\": {\r\n            \"FNUMBER\": \"\"\r\n        },\r\n        \"FPRESETTEXT1\": \"\",\r\n        \"FPRESETTEXT2\": \"\",\r\n        \"FPRESETASSISTANT2\": {\r\n            \"FNumber\": \"\"\r\n        },\r\n        \"FPRESETASSISTANT1\": {\r\n            \"FNumber\": \"\"\r\n        },\r\n        \"FIsGeneratePlanByCostItem\": \"false\",\r\n        \"FSCPCONFIRMERID\": {\r\n            \"FUserID\": \"\"\r\n        },\r\n        \"FSCPCONFIRMDATE\": \"1900-01-01\",\r\n        \"FOrderDiscountAmountFor\": 0,\r\n        \"F_SMGS_Text1\": \"\",\r\n        \"FAllAmountIsByTaxPrice\": \"false\",\r\n        \"F_SMGS_Date\": \"1900-01-01\",\r\n        \"F_SMGS_Base\": {\r\n            \"FNUMBER\": \"\"\r\n        },\r\n        \"FsubHeadSuppiler\": {\r\n            \"FEntryId\": 0,\r\n            \"FORDERID\": {\r\n                \"FNumber\": \"\"\r\n            },\r\n            \"FTRANSFERID\": {\r\n                \"FNumber\": \"\"\r\n            },\r\n            \"FChargeId\": {\r\n                \"FNumber\": \"\"\r\n            }\r\n        },\r\n        \"FsubHeadFinc\": {\r\n            \"FEntryId\": 0,\r\n            \"FACCNTTIMEJUDGETIME\": \"1900-01-01\",\r\n            \"FSettleTypeID\": {\r\n                \"FNumber\": \"\"\r\n            },\r\n            \"FMAINBOOKSTDCURRID\": {\r\n                \"FNumber\": \"\"\r\n            },\r\n            \"FEXCHANGETYPE\": {\r\n                \"FNumber\": \"\"\r\n            },\r\n            \"FExchangeRate\": 0,\r\n            \"FTaxAmountFor\": 0,\r\n            \"FNoTaxAmountFor\": 0,\r\n            \"FISCARRIEDDATE\": \"false\"\r\n        },\r\n        \"FEntityDetail\": [\r\n            {\r\n                \"FEntryID\": 0,\r\n                \"FCOSTID\": {\r\n                    \"FNumber\": \"\"\r\n                },\r\n                \"FMATERIALID\": {\r\n                    \"FNumber\": \"\"\r\n                },\r\n                \"FMaterialDesc\": \"\",\r\n                \"FASSETID\": {\r\n                    \"FNUMBER\": \"\"\r\n                },\r\n                \"FPRICEUNITID\": {\r\n                    \"FNumber\": \"\"\r\n                },\r\n                \"FPrice\": 0,\r\n                \"FPriceQty\": 0,\r\n                \"FTaxPrice\": 0,\r\n                \"FPriceWithTax\": 0,\r\n                \"FEntryTaxRate\": 0,\r\n                \"FTaxCombination\": {\r\n                    \"FNumber\": \"\"\r\n                },\r\n                \"FEntryDiscountRate\": 0,\r\n                \"FSourceBillNo\": \"\",\r\n                \"FSOURCETYPE\": \"\",\r\n                \"FDISCOUNTAMOUNTFOR\": 0,\r\n                \"FNoTaxAmountFor_D\": 0,\r\n                \"FTAXAMOUNTFOR_D\": 0,\r\n                \"FALLAMOUNTFOR_D\": 0,\r\n                \"FINCLUDECOST\": \"false\",\r\n                \"FINCLUDECONTRACTCOMPCOST\": \"false\",\r\n                \"FOUTSTOCKID\": [\r\n                    {\r\n                        \"FNumber\": \"\"\r\n                    }\r\n                ],\r\n                \"FAUXPROPID\": {},\r\n                \"FBUYIVQTY\": 0,\r\n                \"FIVALLAMOUNTFOR\": 0,\r\n                \"FISOUTSTOCK\": \"false\",\r\n                \"FCOSTDEPARTMENTID\": {\r\n                    \"FNUMBER\": \"\"\r\n                },\r\n                \"FLot\": {\r\n                    \"FNumber\": \"\"\r\n                },\r\n                \"FMONUMBER\": \"\",\r\n                \"FMOENTRYSEQ\": 0,\r\n                \"FOPNO\": \"\",\r\n                \"FSEQNUMBER\": \"\",\r\n                \"FOPERNUMBER\": 0,\r\n                \"FPROCESSID\": {\r\n                    \"FNUMBER\": \"\"\r\n                },\r\n                \"FFPRODEPARTMENTID\": {\r\n                    \"FNUMBER\": \"\"\r\n                },\r\n                \"FWWINTYPE\": \"\",\r\n                \"FIsFree\": \"false\",\r\n                \"FStockUnitId\": {\r\n                    \"FNumber\": \"\"\r\n                },\r\n                \"FStockQty\": 0,\r\n                \"FStockBaseQty\": 0,\r\n                \"FPriceBaseDen\": 0,\r\n                \"FStockBaseNum\": 0,\r\n                \"FOrderEntryID\": 0,\r\n                \"FORDERENTRYSEQ\": 0,\r\n                \"FBUYIVINIQTY\": 0,\r\n                \"FBUYIVINIBASICQTY\": 0,\r\n                \"FPushRedQty\": 0,\r\n                \"FIVINIALLAMOUNTFOR\": 0,\r\n                \"FDIFFAMOUNTEXRATE\": 0,\r\n                \"FDIFFALLAMOUNTEXRATE\": 0,\r\n                \"FNORECEIVEAMOUNT\": 0,\r\n                \"FSRCROWID\": 0,\r\n                \"FNOINVOICEAMOUNT\": 0,\r\n                \"FNOINVOICEQTY\": 0,\r\n                \"FROOTSETACCOUNTTYPE\": \"\",\r\n                \"FROOTSOURCETYPE\": \"\",\r\n                \"FTAILDIFFFLAG\": \"false\",\r\n                \"FDIFFAMOUNT\": 0,\r\n                \"F_SMGS_PoPrice\": 0,\r\n                \"FDIFFALLAMOUNT\": 0,\r\n                \"F_SMGS_Text\": \"\",\r\n                \"F_SMGS_Date1\": \"1900-01-01\",\r\n                \"FPRESETENTRYBASE1\": {\r\n                    \"FNUMBER\": \"\"\r\n                },\r\n                \"F_SMGS_Price\": 0,\r\n                \"FPRESETENTRYBASE2\": {\r\n                    \"FNUMBER\": \"\"\r\n                },\r\n                \"F_SMGS_mjdycp\": {\r\n                    \"FNUMBER\": \"\"\r\n                },\r\n                \"FPRESETENTRYTEXT1\": \"\",\r\n                \"FPRESETENTRYTEXT2\": \"\",\r\n                \"FTaxDetailSubEntity\": [\r\n                    {\r\n                        \"FDetailID\": 0,\r\n                        \"FTaxRateId\": {\r\n                            \"FNumber\": \"\"\r\n                        },\r\n                        \"FTaxRate\": 0,\r\n                        \"FTaxAmount_T\": 0,\r\n                        \"FCostPercent\": 0,\r\n                        \"FCostAmount\": 0,\r\n                        \"FVAT\": \"false\",\r\n                        \"FSellerWithholding\": \"false\",\r\n                        \"FBuyerWithholding\": \"false\"\r\n                    }\r\n                ]\r\n            }\r\n        ],\r\n        \"FEntityPlan\": [\r\n            {\r\n                \"FEntryID\": 0,\r\n                \"FENDDATE\": \"1900-01-01\",\r\n                \"FPAYAMOUNTFOR\": 0,\r\n                \"FPAYRATE\": 0,\r\n                \"FPURCHASEORDERID\": 0,\r\n                \"FPAYABLEENTRYID\": 0,\r\n                \"FMATERIALID_P\": {\r\n                    \"FNUMBER\": \"\"\r\n                },\r\n                \"FPRICEUNITID_P\": {\r\n                    \"FNumber\": \"\"\r\n                },\r\n                \"FPRICE_P\": 0,\r\n                \"FQTY_P\": 0,\r\n                \"FPURCHASEORDERNO\": \"\",\r\n                \"FMATERIALSEQ\": 0,\r\n                \"FRELATEHADPAYQTY\": 0,\r\n                \"FNOTVERIFICATEAMOUNT\": 0,\r\n                \"FCOSTID_P\": {\r\n                    \"FNUMBER\": \"\"\r\n                },\r\n                \"FREMARK\": \"\",\r\n                \"FPRESETENTRYBASE_P1\": {\r\n                    \"FNUMBER\": \"\"\r\n                },\r\n                \"FPRESETENTRYBASE_P2\": {\r\n                    \"FNUMBER\": \"\"\r\n                },\r\n                \"FPRESETENTRYTEXT_P1\": \"\",\r\n                \"FPRESETENTRYTEXT_P2\": \"\",\r\n                \"FCOSTDEPARTMENTID_P\": {\r\n                    \"FNUMBER\": \"\"\r\n                }\r\n            }\r\n        ],\r\n        \"FRecInvInfo\": [\r\n            {\r\n                \"FEntryID\": 0\r\n            }\r\n        ]\r\n    }\r\n}\r\n";

            var data2 = client.Save("BOS_Attachment", jsons);

            //费用应付单 3c6f819d78ac4d5981891956c4595b20
            //币别 1
            //单据状态：FDOCUMENTSTATUS B
            //结算组织 FSETTLEORGID   100131
            //业务日期 FDATE  
            //到期日：FENDDATE_H
            //作废状态：FCancelStatus A
            //付款条件：FPayConditon
            //供应商：FSUPPLIERID 
            //业务类型：FBUSINESSTYPE  CG
            //付款组织：FPAYORGID 100131
            //发票号：F_SMGS_Text1  (必填项)
            //开票日期：F_SMGS_Date
            //本位币：FMAINBOOKSTDCURRID 1
        }

        private void Get_dataGridView1()
        {
            string dnhao = comboBox1.Text;
            DataTable dataTable = one.ERP_cjyd2();
            DataTable dataTable2 = one.ERP_cjyd2();
            DataTable dataTable3 = one.ERP_cjyd2();

            foreach(DataGridViewRow obj2 in dataGridView2.Rows)
            {
                dataTable2.Rows.Add(obj2.Cells[1].Value, obj2.Cells[2].Value, obj2.Cells[3].Value, obj2.Cells[4].Value, obj2.Cells[5].Value, obj2.Cells[6].Value, obj2.Cells[7].Value);
            }


            foreach (DataGridViewRow item in dataGridView1.Rows)
            {
                bool index = false;
                foreach (DataRow obj in dataTable.Rows)
                {
                    if (item.Cells[0].Value.ToString() != null)
                    {
                        string temp_DH_1 = obj.ItemArray[0].ToString();
                        string temp_DH_2 = item.Cells[0].Value.ToString();
                        if (temp_DH_1 == temp_DH_2)
                        {
                            index = true;
                            double number_W_1 = double.Parse(obj.ItemArray[2].ToString());
                            double number_W_2 = double.Parse(item.Cells[6].Value.ToString());
                            obj[2] = number_W_1 + number_W_2;

                            double number_V_1 = double.Parse(obj.ItemArray[3].ToString());
                            double number_V_2 = double.Parse(item.Cells[7].Value.ToString());
                            obj[3] = number_V_1 + number_V_2;
                            break;
                        }
                    }
                }
                if (index == false)
                {

                    dataTable.Rows.Add(item.Cells[0].Value, item.Cells[3].Value, item.Cells[6].Value, item.Cells[7].Value, item.Cells[1].Value, item.Cells[2].Value, item.Cells[5].Value);
                }

            }

            int temp = 0;
            foreach(DataRow Table1 in dataTable.Rows)
            {
                foreach (DataRow Table2 in dataTable2.Rows)
                {
                    if (Table1.ItemArray[0].ToString() == Table2.ItemArray[0].ToString())
                    {
                        temp++;
                    }
                }

            }
            if (temp == 0)
            {
                foreach (DataRow Table1 in dataTable.Rows)
                {
                    dataTable3.Rows.Add(Table1.ItemArray[0].ToString(), Table1.ItemArray[1].ToString(), Table1.ItemArray[2].ToString(), Table1.ItemArray[3].ToString(), Table1.ItemArray[4].ToString(), Table1.ItemArray[5].ToString(), Table1.ItemArray[6].ToString());
                }
                foreach (DataRow Table2 in dataTable2.Rows)
                {
                     dataTable3.Rows.Add(Table2.ItemArray[0].ToString(), Table2.ItemArray[1].ToString(), Table2.ItemArray[2].ToString(), Table2.ItemArray[3].ToString(), Table2.ItemArray[4].ToString(), Table2.ItemArray[5].ToString(), Table2.ItemArray[6].ToString());
                }
            }
            else
            {
                foreach (DataRow Table2 in dataTable2.Rows)
                {
                    dataTable3.Rows.Add(Table2.ItemArray[0].ToString(), Table2.ItemArray[1].ToString(), Table2.ItemArray[2].ToString(), Table2.ItemArray[3].ToString(), Table2.ItemArray[4].ToString(), Table2.ItemArray[5].ToString(), Table2.ItemArray[6].ToString());
                }
            }


            dataGridView2.DataSource = dataTable3;
        }



        private void qqq()
        {


            DataGridViewImageColumn deleteColumn = new DataGridViewImageColumn();
            deleteColumn.HeaderText = "删除";
            deleteColumn.Name = "Delete";
            deleteColumn.ImageLayout = DataGridViewImageCellLayout.Zoom;// 你可以设置一个删除图标作为 Image 属性，或者在这里留空并在 CellFormatting 事件中设置  
            dataGridView2.Columns.Add(deleteColumn);

            DataGridViewTextBoxColumn id = new DataGridViewTextBoxColumn();
            id.HeaderText = "发货单号";
            id.DataPropertyName = "id";
            dataGridView2.Columns.Add(id);


            DataGridViewTextBoxColumn distance = new DataGridViewTextBoxColumn();
            distance.HeaderText = "公里数";
            distance.DataPropertyName = "distance";
            dataGridView2.Columns.Add(distance);


            DataGridViewTextBoxColumn weight = new DataGridViewTextBoxColumn();
            weight.HeaderText = "发货重量";
            weight.DataPropertyName = "weight";
            dataGridView2.Columns.Add(weight);


            DataGridViewTextBoxColumn volume = new DataGridViewTextBoxColumn();
            volume.HeaderText = "发货体积";
            volume.DataPropertyName = "volume";
            dataGridView2.Columns.Add(volume);


            DataGridViewTextBoxColumn Customer = new DataGridViewTextBoxColumn();
            Customer.Visible = false;
            Customer.HeaderText = "客户信息";
            Customer.DataPropertyName = "Customer";
            dataGridView2.Columns.Add(Customer);

            DataGridViewTextBoxColumn Delivery_address = new DataGridViewTextBoxColumn();
            Delivery_address.Visible = false;
            Delivery_address.HeaderText = "收货地址";
            Delivery_address.DataPropertyName = "Delivery_address";
            dataGridView2.Columns.Add(Delivery_address);

            DataGridViewTextBoxColumn Main_goods = new DataGridViewTextBoxColumn();
            Main_goods.Visible = false;
            Main_goods.HeaderText = "主要货物";
            Main_goods.DataPropertyName = "Main_goods";
            dataGridView2.Columns.Add(Main_goods);







            //运单
            DataGridViewTextBoxColumn Invoice_number = new DataGridViewTextBoxColumn();
            Invoice_number.HeaderText = "发货通知单号";
            Invoice_number.DataPropertyName = "Invoice_number";
            dataGridView4.Columns.Add(Invoice_number);


            DataGridViewTextBoxColumn Customer3 = new DataGridViewTextBoxColumn();
            Customer3.HeaderText = "客户";
            Customer3.DataPropertyName = "Customer";
            dataGridView4.Columns.Add(Customer3);


            DataGridViewTextBoxColumn Delivery_address2 = new DataGridViewTextBoxColumn();
            Delivery_address2.HeaderText = "送货地址";
            Delivery_address2.DataPropertyName = "Delivery_address";
            dataGridView4.Columns.Add(Delivery_address2);


            DataGridViewTextBoxColumn Main_goods2 = new DataGridViewTextBoxColumn();
            Main_goods2.HeaderText = "主要货物";
            Main_goods2.DataPropertyName = "Main_goods";
            dataGridView4.Columns.Add(Main_goods2);

            DataGridViewTextBoxColumn Creation_date = new DataGridViewTextBoxColumn();
            Creation_date.HeaderText = "创建日期";
            Creation_date.DataPropertyName = "Creation_date";
            dataGridView4.Columns.Add(Creation_date);

            DataGridViewTextBoxColumn Delivery_number = new DataGridViewTextBoxColumn();
            Delivery_number.HeaderText = "运单号";
            Delivery_number.DataPropertyName = "Delivery_number";
            dataGridView4.Columns.Add(Delivery_number);

            DataGridViewTextBoxColumn Carrier = new DataGridViewTextBoxColumn();
            Carrier.HeaderText = "承运单位";
            Carrier.DataPropertyName = "Carrier";
            dataGridView4.Columns.Add(Carrier);

            DataGridViewTextBoxColumn Train_number = new DataGridViewTextBoxColumn();
            Train_number.HeaderText = "车次";
            Train_number.DataPropertyName = "Train_number";
            dataGridView4.Columns.Add(Train_number);

            DataGridViewTextBoxColumn Kilometers = new DataGridViewTextBoxColumn();
            Kilometers.HeaderText = "公里数";
            Kilometers.DataPropertyName = "Kilometers";
            dataGridView4.Columns.Add(Kilometers);
            
            DataGridViewTextBoxColumn Shipping_cost = new DataGridViewTextBoxColumn();
            Shipping_cost.HeaderText = "运费";
            Shipping_cost.DataPropertyName = "Shipping_cost";
            dataGridView4.Columns.Add(Shipping_cost);

            DataGridViewTextBoxColumn License_plate = new DataGridViewTextBoxColumn();
            License_plate.HeaderText = "车牌号";
            License_plate.DataPropertyName = "License_plate";
            dataGridView4.Columns.Add(License_plate);
        }

        /// <summary>
        /// 根据下拉列表修改显示的车辆信息
        /// </summary>
        private void Cet_vehicle()
        {
            //车辆表头
            DataGridViewTextBoxColumn cl_id = new DataGridViewTextBoxColumn();
            cl_id.HeaderText = "车辆id";
            cl_id.DataPropertyName = "cl_id";
            dataGridView3.Columns.Add(cl_id);

            DataGridViewTextBoxColumn cl_cp = new DataGridViewTextBoxColumn();
            cl_cp.HeaderText = "车牌号";
            cl_cp.DataPropertyName = "cl_cp";
            dataGridView3.Columns.Add(cl_cp);


            DataGridViewTextBoxColumn cl_cc = new DataGridViewTextBoxColumn();
            cl_cc.HeaderText = "车长";
            cl_cc.DataPropertyName = "cl_cc";
            dataGridView3.Columns.Add(cl_cc);


            DataGridViewTextBoxColumn cl_ck = new DataGridViewTextBoxColumn();
            cl_ck.HeaderText = "车宽";
            cl_ck.DataPropertyName = "cl_ck";
            dataGridView3.Columns.Add(cl_ck);

            DataGridViewTextBoxColumn cl_dw = new DataGridViewTextBoxColumn();
            cl_dw.HeaderText = "吨位";
            cl_dw.DataPropertyName = "cl_dw";
            dataGridView3.Columns.Add(cl_dw);

            DataGridViewTextBoxColumn cl_zz = new DataGridViewTextBoxColumn();
            cl_zz.HeaderText = "载重";
            cl_zz.DataPropertyName = "cl_zz";
            dataGridView3.Columns.Add(cl_zz);

            DataGridViewTextBoxColumn cl_rj = new DataGridViewTextBoxColumn();
            cl_rj.HeaderText = "容积";
            cl_rj.DataPropertyName = "cl_rj";
            dataGridView3.Columns.Add(cl_rj);


            string number =comboBox2.SelectedValue.ToString();
            int number2 = int.Parse(number);
            var item = db.CLSJ.ToList();
            if (number2 != 0)
            {
                item = item.Where(x => x.cl_ss == number2).ToList();
            }
            DataTable dataTable = one.CLSJ();
            foreach (CLSJ clsj in item)
            {
                dataTable.Rows.Add(clsj.cl_id, clsj.cl_cp, clsj.cl_cc, clsj.cl_ck, clsj.cl_dw,clsj.cl_zz, clsj.cl_rj);
            }
            dataGridView3.DataSource = dataTable;

            
        }
        /// <summary>
        /// 下拉列表添加承运单位
        /// </summary>
        private void Get_carrier()
        {
            var item = db.CYDW.ToList();
            DataTable dataTable = one.CYDW();
            foreach (CYDW cydw in item)
            {
                dataTable.Rows.Add(cydw.cy_id, cydw.cy_name);
            }
            comboBox2.DataSource = dataTable;
            comboBox2.DisplayMember = "name";
            comboBox2.ValueMember = "id";
        }
        /// <summary>
        /// 获取erp发货通知单信息
        /// </summary>
        private void Get_Shipping_note()
        {
           

            DateTime now = DateTime.Now;
            string currentDateTime = now.ToString("yyyy-MM-dd HH:mm:ss");
            K3CloudApi client = new K3CloudApi();
            //用于记录结果
            StringBuilder Info = new StringBuilder();
            //业务对象标识
            string formId = "SAL_DELIVERYNOTICE";
            //查询字段集合，即返回哪些数据，不能为空，根据不同业务单据填写不同的字段名，以下仅为示例
            string fieldKeys = "FBillNo,F_SMGS_BaseProperty7,FReceiveAddress,F_SMGS_KM,F_SMGS_Integer4,FMaterialName,F_SMGS_YFKG,F_SMGS_Decimal1";
            //请求参数，示例使用的是SDK提供的模板类，还可以使用字符串拼接等方式
            var ZBLx = comboBox1.Text;
            var param = new QueryParam()
            {
                FormId = formId,
                FieldKeys = fieldKeys,
                FilterString = "FBillNo like'%" + ZBLx + "%'and FBillTypeID ='193822715afc48aa9fa6d6beca7700ab'",
                TopRowCount = 0,
                StartRow = 0,
                Limit = 120,
                OrderString = "FBillNo",
            };
            //调用接口
            var result = client.ExecuteBillQuery(param.ToJson());
            if (dataGridView1.Columns.Count != 0)
            {
                dataGridView1.Columns.Clear();
            }
            /* JsonSerializerSettings settings = new JsonSerializerSettings();
             string jsongStr = JsonConvert.SerializeObject(result, settings);*/
            //转换成标准文档并遍历
            DataTable dataTable = one.ERP_fh();


            //待选择表头

            DataGridViewTextBoxColumn id2 = new DataGridViewTextBoxColumn();
            id2.HeaderText = "发货单号";
            id2.DataPropertyName = "id";
            dataGridView1.Columns.Add(id2);


            DataGridViewTextBoxColumn client1 = new DataGridViewTextBoxColumn();
            client1.HeaderText = "客户";
            client1.DataPropertyName = "client";
            dataGridView1.Columns.Add(client1);


            DataGridViewTextBoxColumn address = new DataGridViewTextBoxColumn();
            address.HeaderText = "收货地址";
            address.DataPropertyName = "address";
            dataGridView1.Columns.Add(address);


            DataGridViewTextBoxColumn distance2 = new DataGridViewTextBoxColumn();
            distance2.HeaderText = "公里数";
            distance2.DataPropertyName = "distance";
            dataGridView1.Columns.Add(distance2);

            DataGridViewTextBoxColumn Material = new DataGridViewTextBoxColumn();
            Material.HeaderText = "客户信息";
            Material.DataPropertyName = "Material";
            dataGridView1.Columns.Add(Material);

            DataGridViewTextBoxColumn quantity = new DataGridViewTextBoxColumn();
            quantity.HeaderText = "货物名称";
            quantity.DataPropertyName = "quantity";
            dataGridView1.Columns.Add(quantity);

            DataGridViewTextBoxColumn weight2 = new DataGridViewTextBoxColumn();
            weight2.HeaderText = "发货重量";
            weight2.DataPropertyName = "weight";
            dataGridView1.Columns.Add(weight2);

            DataGridViewTextBoxColumn volume2 = new DataGridViewTextBoxColumn();
            volume2.HeaderText = "发货体积";
            volume2.DataPropertyName = "volume";
            dataGridView1.Columns.Add(volume2);

            
            foreach (var item in result)
            {
                dataTable.Rows.Add(item[0], item[1], item[2], item[3], item[4], item[5], item[6], item[7]);
            }
            dataGridView1.DataSource = dataTable;

           
        }

        private void Get_Shipping_note_number()
        {
            DateTime now = DateTime.Now;
            string currentDateTime = now.ToString("yyyy-MM-dd HH:mm:ss");
            K3CloudApi client = new K3CloudApi();
            //用于记录结果
            StringBuilder Info = new StringBuilder();
            //业务对象标识
            string formId = "SAL_DELIVERYNOTICE";
            //查询字段集合，即返回哪些数据，不能为空，根据不同业务单据填写不同的字段名，以下仅为示例
            string fieldKeys = "FBillNo,F_SMGS_BaseProperty7,FReceiveAddress,F_SMGS_KM,F_SMGS_Integer4,FMaterialName,F_SMGS_YFKG,F_SMGS_Decimal1";
            //请求参数，示例使用的是SDK提供的模板类，还可以使用字符串拼接等方式
            var ZBLx = comboBox1.Text;
            var param = new QueryParam()
            {
                FormId = formId,
                FieldKeys = fieldKeys,
                FilterString = "FBillNo like'%" + ZBLx + "%'and FBillTypeID ='193822715afc48aa9fa6d6beca7700ab'and FPlanDeliveryDate >'" + currentDateTime + "'and FCancelStatus='A'",
                TopRowCount = 0,
                StartRow = 0,
                Limit = 120,
                OrderString = "FBillNo",
            };
            //调用接口
            var result = client.ExecuteBillQuery(param.ToJson());
            /* JsonSerializerSettings settings = new JsonSerializerSettings();
             string jsongStr = JsonConvert.SerializeObject(result, settings);*/
            //转换成标准文档并遍历
            DataTable dataTable = one.ERP_id();
            foreach (var item in result)
            {
                bool index = false;
                if (dataTable.Rows.Count == 0)
                {
                    dataTable.Rows.Add(item[0], item[1]);
                }
                else
                {
                    foreach (DataRow obj in dataTable.Rows)
                    {
                        string a = obj.ItemArray[0].ToString();
                        string b = item[0].ToString();
                        if (a == b)
                        {
                            index = true;
                            break;
                            
                        }
                    }
                    if (index == false)
                    {
                        dataTable.Rows.Add(item[0], item[1]);
                    }
                    
                }
                
            }
            comboBox1.DataSource = dataTable;
            comboBox1.DisplayMember = "id";
        }

        private void dataGridView2_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            if (dataGridView2.Columns[e.ColumnIndex].Name == "Delete")
            {
                // 假设你的数据源是一个 BindingList<T> 或其他支持删除操作的集合  
                // 你需要根据你的数据源类型来编写删除逻辑  
                // 例如，如果你的数据源是一个 List<MyData>，你可能需要这样做：  
                // MyData itemToDelete = (MyData)dataGridView1.Rows[e.RowIndex].DataBoundItem;  
                // myDataList.Remove(itemToDelete); // 假设 myDataList 是你的数据源  

                // 对于简单示例，我们直接删除 DataGridView 的行  
                dataGridView2.Rows.RemoveAt(e.RowIndex);

                // 注意：如果你正在使用数据源绑定，直接删除 DataGridView 的行可能不会更新数据源  
                // 你需要更新你的数据源，然后重新绑定到 DataGridView，或者调用 DataGridView 的 Refresh 方法（如果适用）  
            }
        }

        

        private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            
        }

        private void button4_Click(object sender, EventArgs e)
        {
            Get_Shipping_note();
        }

        private void comboBox2_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (label2.Text == "1")
            {
                Cet_vehicle();
            }
            
        }
    }
}
